/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.market.web.controller;

import java.io.IOException;
import org.glassfish.sse.api.ServerSentEvent;
import org.glassfish.sse.api.ServerSentEventConnection;
import org.glassfish.sse.api.ServerSentEventData;
import org.glassfish.sse.api.ServerSentEventHandler;

/**
 *
 * @author Mai
 */
@ServerSentEvent("/invUpdate")
public class InventoryConnection extends ServerSentEventHandler {

    @Override
    public void onConnected(ServerSentEventConnection connection) {
        super.onConnected(connection); //To change body of generated methods, choose Tools | Templates.
        System.out.println("------->new connection");
    }
    
    public void send(ServerSentEventData data)
    {
        try
        {
            System.out.println("here sending");
            connection.sendMessage(data);
            System.out.println("end sending");
        }
        catch(IOException ex)
        {
            System.out.println("something wrong");
            connection.close();
        }
    }
    
    
    public void send(String msg) {
        try {
            connection.sendMessage(msg);
        } catch (IOException ex) {
            connection.close();
        }
    }
}
